package com.css.fxfzmh.config.filter;

import com.css.fxfzmh.web.filter.SessionFilter;
import com.css.fxfzmh.config.property.FxfzConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.servlet.DispatcherType;

@Configuration
public class FilterConfig {

    @Autowired
    FxfzConfig fxfzConfig;
    @Bean
    public FilterRegistrationBean sessionFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC);
        registration.setFilter(new SessionFilter());
        registration.addUrlPatterns(fxfzConfig.getSessionUrlPatterns());
        registration.addInitParameter("ignoreUrl",fxfzConfig.getSessionIgnoreUrlPatterns());
        registration.setName("sessionFilter");
        registration.addInitParameter("charset", "UTF-8");
        registration.setOrder(fxfzConfig.getSessionFilterOrder());
        return registration;
    }

    /*@Bean
    public FilterRegistrationBean actuatorFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC);
        registration.setFilter(new ActuatorFilter());
        registration.addUrlPatterns("/actuator/*,/druid/*");
        registration.setName("actuatorFilter");
        registration.addInitParameter("charset",CacheConstant.DEFAULT_CHARSET);
        return registration;
    }*/

    /*@Bean
    public FilterRegistrationBean documentSessionFilterRegistration() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE, DispatcherType.ASYNC);
        registration.setFilter(new DocumentSessionFilter());
        registration.addUrlPatterns(FxfzConfig.getWpsUrlPatterns());
        registration.setName("documentSessionFilter");
        return registration;
    }*/
}
